package com.woniu.controller;

import com.woniu.entity.User;
import com.woniu.entity.UserCart;
import com.woniu.service.UserService;
import com.woniu.util.JWTUtil;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public ResData<?> login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping("/addCart")
    public ResData<?> add(UserCart userCart, HttpServletRequest request){
        String token = request.getHeader("token");
        return userService.addCart(userCart,token);
    }

    @GetMapping("/queryUserCart")
    public ResData<?> queryUserCart(HttpServletRequest request){
        String token = request.getHeader("token");
        return userService.queryUserCart(token);
    }
}
